package demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-10-18
 * Time: 16:59
 */

// 通过饿汉模式构造单例模式

class Singleton{
    private static Singleton instance = new Singleton();//类加载时候就new

    //对外公开可以访问的方法
    public static Singleton getInstance(){
        return instance;
    }

    //私有化构造方法，让外面的类不可以new多个对象
    private Singleton(){

    }
}
public class Demo1 {
    public static void main(String[] args) {
        Singleton t1 = Singleton.getInstance();
        Singleton t2 = Singleton.getInstance();

        System.out.println(t1 == t2);
    }
}
